package com.yuxi.Controller.Impl;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import com.google.gson.Gson;
import com.mchange.v2.c3p0.stmt.GooGooStatementCache;
import com.yuxi.Config.ConfigStatic;
import com.yuxi.Controller.InformationSubController;
import com.yuxi.Controller.UserPrisonAreaInformationController;
import com.yuxi.Dao.CommentRecordDao;
import com.yuxi.Dao.EvaluationRecordDao;
import com.yuxi.Dao.InformationDao;
import com.yuxi.Dao.PrisonStructureDao;
import com.yuxi.Dao.TaskDispatchDao;
import com.yuxi.Entity.CommentRecord;
import com.yuxi.Entity.EvaluationRecord;
import com.yuxi.Entity.Information;
import com.yuxi.Entity.InformationPort;
import com.yuxi.Entity.PrisonStructure;
import com.yuxi.Entity.TaskDispatch;
import com.yuxi.Entity.TaskInformationView;
import com.yuxi.Entity.UserInfo;
import com.yuxi.Request.InformationQuery;
import com.yuxi.Request.Page;
import com.yuxi.Request.PageReturn;
import com.yuxi.Response.Msg;
import com.yuxi.Response.Obj;
import com.yuxi.Service.PrisonService;
import com.yuxi.Service.UserInformationService;
import com.yuxi.Service.UserQueryService;
import com.yuxi.Service.UserService;
import com.yuxi.Service.UserSubService;
import com.yuxi.Util.IPUtil;
import com.yuxi.view.UserPowerView;

import sun.net.util.IPAddressUtil;
@Controller
public class UserPrisonAreaInformationControllerImpl implements UserPrisonAreaInformationController {
	@Autowired
	private UserInformationService userInformationService;
	@Autowired
	private UserService userService;
	@Autowired
	private PrisonService prisonService;
	@Autowired
	private UserQueryService  userQueryService;
	@Autowired
	private UserSubService userSubService;
	@Autowired
	private PrisonStructureDao prisonStructureDao;
	@Autowired
	private TaskDispatchDao taskDispatchDao;
	@Autowired
	private InformationDao informationDao;
	@Autowired
	private CommentRecordDao  commentRecordDao;
	@Autowired
	private EvaluationRecordDao  evaluationRecordDao;
	@Autowired
	private InformationSubController  informationSubController;
	private Gson gson=new Gson();
	@Override
	public String addInformation(Information information, HttpSession session,HttpServletRequest request) {		
		boolean f=userInformationService.userAddInformation(information, userService.getCurLoginUser(session), IPUtil.getIpAddr(request));
		if(f){
			Msg rs=new Msg(true, "添加信息成功", System.currentTimeMillis(), null, "添加信息");
			return gson.toJson(rs);
		}else{
			Msg rs=new Msg(false, "添加信息失败", System.currentTimeMillis(), "1001", "添加信息");
			return gson.toJson(rs);
		}
		
	}

	@Override
	public String userUpdataInformation(Information information, HttpSession session,HttpServletRequest request) {
		try{
			String ip=IPUtil.getIpAddr(request);
			UserInfo userInfo=userService.getCurLoginUser(session);
			
			if(userInformationService.userUpdataInformation(information, userInfo, ip)){
				Msg msg=new Msg(true, "更改信息成功", System.currentTimeMillis(), null, "修改信息");
				return gson.toJson(msg);
			}else{
				Msg msg=new Msg(false, "更改信息失败", System.currentTimeMillis(), "10001", "修改信息");
				return gson.toJson(msg);
			}
		}catch(Exception e){
			Msg msg=new Msg(false, "更改信息失败", System.currentTimeMillis(), "10002", "修改信息");
			return gson.toJson(msg);
		}	
	}

	@Override
	public String userDelInformationById(Information information, HttpSession session,HttpServletRequest request) {
		try{
			String ip=IPUtil.getIpAddr(request);
			UserInfo userInfo=userService.getCurLoginUser(session);
			if(userInformationService.userDelInformationById(information, userInfo, ip)){
				Msg msg=new Msg(true, "删除信息成功", System.currentTimeMillis(), null, "删除信息");
				return gson.toJson(msg);
			}else{
				Msg msg=new Msg(false, "删除信息失败", System.currentTimeMillis(), "10001", "删除信息");
				return gson.toJson(msg);
			}
		}catch(Exception e){
			Msg msg=new Msg(false, "删除信息失败", System.currentTimeMillis(), "10002", "删除信息");
			return gson.toJson(msg);
		}	
	}

	@Override
	public String getUserInformationById(int informationId, HttpSession session) {		
		try{
			Information  info=userInformationService.userGetInformationById(informationId);
			Obj obj=new Obj(true, "获取信息成功", info, System.currentTimeMillis(), null, "查看信息详情");
			return gson.toJson(obj);
		}catch(Exception e){
			Obj obj=new Obj(false, "获取信息失败", null, System.currentTimeMillis(), "1001", "查看信息详情");
			return gson.toJson(obj);
		}
	}

	@Override
	public String infoTogether(String enId, String temId, HttpServletRequest request, HttpSession session) {
		try{
			String ip=IPUtil.getIpAddr(request);
			UserInfo u=userService.getCurLoginUser(session);
			String[] infoIdListStr=enId.split(",");		
			Information newInfo=userInformationService.userInfoTogether(infoIdListStr, Integer.parseInt(temId), u, ip);
			if(newInfo!=null){
				Obj obj=new Obj(true, "合并信息成功", newInfo, System.currentTimeMillis(), null, "信息合并");
				System.out.println(obj.toString()+"dfdfd");
				session.setAttribute("infoTogether",obj);
				return gson.toJson(obj);
			}else{
				Obj obj=new Obj(false, "合并信息失败", null, System.currentTimeMillis(), "10001", "信息合并");
				return gson.toJson(obj);
			}
		}catch(Exception e){
			Obj obj=new Obj(false, "合并信息失败", null, System.currentTimeMillis(), "10002", "信息合并");
			return gson.toJson(obj);
		}

	}

	@Override
	public String inputLiable(int informationId, String personLiableId, String perSonLiableName, String remark,Long overTime,
			HttpSession session, HttpServletRequest request) {
		
		return curTaskDispatch(ConfigStatic.FLOWTABLE.get("FirstCheck"),informationId, personLiableId, perSonLiableName, remark, overTime, session, request);
	}
	
	private String curTaskDispatch(int flowId,int informationId, String personLiableId, String perSonLiableName, String remark,Long overTime,
			HttpSession session, HttpServletRequest request){
		try{
			String[] idArray=personLiableId.split(",");
			String[] nameArray=perSonLiableName.split(",");
			UserInfo u=userService.getCurLoginUser(session);

			String ip=IPUtil.getIpAddr(request);
			Information information=informationDao.getInformationById(informationId);
			information.setZeRenPersonId(","+personLiableId);
			information.setZeRenPerSonNames(","+perSonLiableName);
			information.setZeRenTime(Long.toString(overTime));
			information.setZeRenRemark(remark);
			information.setTaskDispatchName(u.getUserName());
			information.setTaskDispatchTime(Long.toString(System.currentTimeMillis()));
			informationDao.modifyInformation(information);
			userSubService.subToCurTaskDispatch(informationId, u, ip,"");
			Msg msg=new Msg(true, "提交即时任务派遣成功", System.currentTimeMillis(), null, "提交即时任务派遣");
			return gson.toJson(msg);
		}catch(Exception e){
			e.printStackTrace();
			Msg msg=new Msg(false, "提交即时任务派遣失败", System.currentTimeMillis(), "10001", "提交即时任务派遣");
			return gson.toJson(msg);
		}
	}

	@Override
	public String taskDispatch(int informationId, String personLiableId, String perSonLiableName, String remark,
			Long overTime, HttpServletRequest request, HttpSession session) {
		return modifyTaskZen(0,informationId, personLiableId, perSonLiableName, remark, overTime, request, session);
	}

	@Override
	public String curTaskDispatch(int informationId, String personLiableId, String perSonLiableName, String remark,
			Long overTime, HttpServletRequest request, HttpSession session) {
		return modifyTaskZen(1,informationId, personLiableId, perSonLiableName, remark, overTime, request, session);
	}
	
	
	private String modifyTaskZen(int type,int informationId, String personLiableId, String perSonLiableName, String remark,
			Long overTime, HttpServletRequest request, HttpSession session){
		try{
			String ip=IPUtil.getIpAddr(request);
			Information information=informationDao.getInformationById(informationId);
			information.setZeRenPersonId(","+personLiableId);
			information.setZeRenPerSonNames(","+perSonLiableName);
			information.setZeRenTime(Long.toString(overTime));
			information.setZeRenRemark(remark);
			informationDao.modifyInformation(information);
			if(type==1){
				informationSubController.curTaskSubToTaskFinish(informationId, session, request);
			}else{
				informationSubController.taskSubToTaskFinish(informationId, session, request);
			}
			
			Msg msg=new Msg(true, "修改成功", System.currentTimeMillis(), null, "任务派遣修改责任人");
			return gson.toJson(msg);
		}catch(Exception e){
			Msg msg=new Msg(false, "修改失败", System.currentTimeMillis(), "10001", "任务派遣修改责任人");
			return gson.toJson(msg);
		}
	}

	@Override
	public String inputTaskFinshContext(int inforId,int taskId,String context, HttpServletRequest request, HttpSession session) {
		UserInfo u=userService.getCurLoginUser(session);
		String ip=IPUtil.getIpAddr(request);
		if(userInformationService.inputTaskFinsh(inforId, taskId, context, u, ip)){
			List<TaskDispatch> i=taskDispatchDao.getTaskDispatchByInfoId(inforId, 0);
			if(i==null||i.size()==0){
				userSubService.subToInfoComment(inforId, u, ip);
			}
			Msg msg=new Msg(true, "录入任务完成情况成功", System.currentTimeMillis(), null, "录入任务完成情况");
			return gson.toJson(msg);
		}else{
			Msg msg=new Msg(false, "录入任务完成情况失败", System.currentTimeMillis(), "10001", "录入任务完成情况");
			return gson.toJson(msg);
		}
		
		
	}

	@Override
	public String getInfoTogether(HttpSession session) {		
		Gson gson=new Gson();
		Obj o=(Obj) session.getAttribute("infoTogether");
		System.out.println(gson.toJson(o));
		return gson.toJson(o);
	}

	@Override
	public String userComment(int informationId, String text, String qualityLvId, String taskLvId,String qualityLvName,String taskLvName ,String completeText , HttpServletRequest request,
			HttpSession session) {
		UserInfo u=userService.getCurLoginUser(session);
		String ip=IPUtil.getIpAddr(request);
		if(userInformationService.commentInfo(informationId, text, qualityLvId,taskLvId,qualityLvName,taskLvName,completeText, u, ip)){
			Msg msg=new Msg(true, "点评成功", System.currentTimeMillis(), null, "点评信息");
			return gson.toJson(msg);
		}else{
			Msg msg=new Msg(false, "点评信息失败", System.currentTimeMillis(), "10001", "点评信息");
			return gson.toJson(msg);
		}
	}
	
	@Override
	public String addEvaluate(int id, String text,String peopleId,String peopleName, HttpSession session,HttpServletRequest req) {
		UserInfo userInfo=userService.getCurLoginUser(session);
		String ip=IPUtil.getIpAddr(req);
		if(userInformationService.ratedInfo(id, text, userInfo, ip,peopleId,peopleName)){
			userSubService.subToInfoFinish(id, userInfo, ip);
			Msg msg=new Msg(true, "评价成功", System.currentTimeMillis(), null, "评价任务完成情况");
			return gson.toJson(msg);
		}else{
			Msg msg=new Msg(false, "评价失败", System.currentTimeMillis(), "10001", "评价任务完成情况");
			return gson.toJson(msg);		
		}
	}

	@Override
	public String getAlreadyDoInfoFlow(InformationQuery inforQuery, Page<Information> p,int flowId,HttpSession session,
			HttpServletRequest request) {
		try {
			
			Page<Information> rsp=new Page<Information>();
			List<UserInfo> userInfos=new ArrayList<>();
			if(!inforQuery.getIntputNumber().equals("0")){
				userInfos=prisonService.getUserListByAccountOrName((inforQuery.getIntputNumber()));
			 	if (userInfos==null) {
			 		Page<Information> p1=new Page<Information>();
			 		return gson.toJson(p1);
				}else{
					inforQuery.setIntputName(userInfos.get(0).getUserName());
					inforQuery.setUserId(Integer.toString(userInfos.get(0).getUserId()));
				}
			}else{
				if (!inforQuery.getIntputName().equals("%")) {
					userInfos=prisonService.getUserListByAccountOrName((inforQuery.getIntputName()));
					if (userInfos==null) {
				 		Page<Information> p1=new Page<Information>();
				 		return gson.toJson(p1);
					}else{
						inforQuery.setIntputName(userInfos.get(0).getUserName());
						inforQuery.setUserId(Integer.toString(userInfos.get(0).getUserId()));
					}
				}
			}
			if(!inforQuery.getFinisPersonNum().equals("0")){
				userInfos =prisonService.getUserListByAccountOrName((inforQuery.getFinisPersonNum()));
			 	if (userInfos==null) {
			 		return gson.toJson(rsp);
				}else{
					inforQuery.setFinisPerson(userInfos.get(0).getUserName());
				}
			}
			UserInfo user=userService.getCurLoginUser(session);
			UserPowerView userPowerView=userService.getUserPowerViewByUserId(user);
			
			List<InformationPort> ports =userPowerView.getPowerPort();
			String ip=IPUtil.getIpAddr(request);
			PageReturn pReturn=(PageReturn)session.getAttribute("pageReturn");
			if (pReturn!=null) {
				if (pReturn.isOpen()==true) {
					if (pReturn.getUrl().equals(request.getServletPath())) {
						p.setCurrentPage(pReturn.getPageNum());
						inforQuery=pReturn.getInformationQuery();
						pReturn.setOpen(false);
					}
				}
				
			}
			inforQuery.setStructure(Integer.toString(userPowerView.getMaxStructure().getId()));
			rsp=userQueryService.getInformationAlreadyDoByFLow(inforQuery, flowId, user, ip, p,ports);
			PageReturn pageReturn=new PageReturn();
			pageReturn.setOpen(false);
			pageReturn.setPageNum(p.getCurrentPage());
			pageReturn.setInformationQuery(inforQuery);
			pageReturn.setUrl(request.getServletPath());
			session.setAttribute("pageReturn", pageReturn);	
			return gson.toJson(rsp);
		} catch (Exception e) {
			e.printStackTrace();
			Page<Information> rsp=new Page<Information>();
			return gson.toJson(rsp);
		}
		
	}
	@Override
	public String getAllInfo(InformationQuery inforQuery, Page<Information> p,String structValue,int structId,HttpSession session,
			HttpServletRequest request  ) {
		try {
			
			PrisonStructure pStructure=new PrisonStructure();
			pStructure.setId(structId);
			pStructure.setValue(structValue);
			Page<Information> rsp=new Page<Information>();
			List<UserInfo> userInfos=new ArrayList<>();
			if(!inforQuery.getIntputNumber().equals("0")){
				
				userInfos=prisonService.getUserListByAccountOrName((inforQuery.getIntputNumber()));
			 	if (userInfos==null) {
			 		Page<Information> p1=new Page<Information>();
			 		return gson.toJson(p1);
				}else{
					inforQuery.setIntputName(userInfos.get(0).getUserName());
					inforQuery.setUserId(Integer.toString(userInfos.get(0).getUserId()));
				}
			}else{
				if (!inforQuery.getIntputName().equals("%")) {
					userInfos=prisonService.getUserListByAccountOrName((inforQuery.getIntputName()));
					if (userInfos==null) {
				 		Page<Information> p1=new Page<Information>();
				 		return gson.toJson(p1);
					}else{
						inforQuery.setIntputName(userInfos.get(0).getUserName());
						inforQuery.setUserId(Integer.toString(userInfos.get(0).getUserId()));
					}
				}
				
				
			}
			 
			if(!inforQuery.getFinisPersonNum().equals("0")){
				userInfos =prisonService.getUserListByAccountOrName((inforQuery.getFinisPersonNum()));
			 	if (userInfos==null) {
			 		return gson.toJson(rsp);
				}else{
					inforQuery.setFinisPerson(userInfos.get(0).getUserName());
				}
			}
			PageReturn pReturn=(PageReturn)session.getAttribute("pageReturn");
			if (pReturn!=null) {
				if (pReturn.isOpen()==true) {
					if (pReturn.getUrl().equals(request.getServletPath())) {
						p.setCurrentPage(pReturn.getPageNum());
						inforQuery=pReturn.getInformationQuery();
						pReturn.setOpen(false);
					}
				}
				
			}
			PageReturn pageReturn=new PageReturn();
			pageReturn.setOpen(false);
			pageReturn.setPageNum(p.getCurrentPage());
			pageReturn.setInformationQuery(inforQuery);
			pageReturn.setUrl(request.getServletPath());
			session.setAttribute("pageReturn", pageReturn);	
			rsp=userQueryService.getAllInformation(inforQuery,  p,pStructure);
			return gson.toJson(rsp);
		} catch (Exception e) {
			e.printStackTrace();
			Page<Information> rsp=new Page<Information>();
			return gson.toJson(rsp);
		}
		
	}
	@Override
	public String getLookCommentInfo(InformationQuery inforQuery, Page<Information> p,HttpSession session,
			HttpServletRequest request) {
		try {
			Page<Information> rsp=new Page<Information>();
			if(!inforQuery.getIntputNumber().equals("0")){
				List<UserInfo> userInfos =prisonService.getUserListByAccountOrName((inforQuery.getIntputNumber()));
			 	if (userInfos==null) {
			 		return gson.toJson(rsp);
				}else{
					inforQuery.setIntputName(userInfos.get(0).getUserName());
				}
			}
			if(!inforQuery.getFinisPersonNum().equals("0")){
				List<UserInfo> userInfos =prisonService.getUserListByAccountOrName((inforQuery.getFinisPersonNum()));
			 	if (userInfos==null) {
			 		return gson.toJson(rsp);
				}else{
					inforQuery.setFinisPerson(userInfos.get(0).getUserName());
				}
			}
			PageReturn pReturn=(PageReturn)session.getAttribute("pageReturn");
			if (pReturn!=null) {
				if (pReturn.isOpen()==true) {
					if (pReturn.getUrl().equals(request.getServletPath())) {
						p.setCurrentPage(pReturn.getPageNum());
						inforQuery=pReturn.getInformationQuery();
						pReturn.setOpen(false);
					}
				}
				
			}
			
			UserInfo user=userService.getCurLoginUser(session);
			rsp=userQueryService.getLookCommentInformation(inforQuery,  p,user);
			PageReturn pageReturn=new PageReturn();
			pageReturn.setOpen(false);
			pageReturn.setPageNum(rsp.getCurrentPage());
			pageReturn.setInformationQuery(inforQuery);
			pageReturn.setUrl(request.getServletPath());
			session.setAttribute("pageReturn", pageReturn);	
			return gson.toJson(rsp);
		} catch (Exception e) {
			Page<Information> rsp=new Page<Information>();
			return gson.toJson(rsp);
		}
		
	}
	@Override
	public String getLookEvaluationInfo(InformationQuery inforQuery, Page<Information> p,HttpSession session,
			HttpServletRequest request) {
		try {
			Page<Information> rsp=new Page<Information>();
			if(!inforQuery.getIntputNumber().equals("0")){
				List<UserInfo> userInfos =prisonService.getUserListByAccountOrName((inforQuery.getIntputNumber()));
			 	if (userInfos==null) {
			 		return gson.toJson(rsp);
				}else{
					inforQuery.setIntputName(userInfos.get(0).getUserName());
				}
			}
			if(!inforQuery.getFinisPersonNum().equals("0")){
				List<UserInfo> userInfos =prisonService.getUserListByAccountOrName((inforQuery.getFinisPersonNum()));
			 	if (userInfos==null) {
			 		return gson.toJson(rsp);
				}else{
					inforQuery.setFinisPerson(userInfos.get(0).getUserName());
				}
			}
			PageReturn pReturn=(PageReturn)session.getAttribute("pageReturn");
			if (pReturn!=null) {
				if (pReturn.isOpen()==true) {
					if (pReturn.getUrl().equals(request.getServletPath())) {
						p.setCurrentPage(pReturn.getPageNum());
						inforQuery=pReturn.getInformationQuery();
						pReturn.setOpen(false);
					}
				}
				
			}
			PageReturn pageReturn=new PageReturn();
			pageReturn.setOpen(false);
			pageReturn.setPageNum(p.getCurrentPage());
			pageReturn.setInformationQuery(inforQuery);
			pageReturn.setUrl(request.getServletPath());
			session.setAttribute("pageReturn", pageReturn);	
			UserInfo user=userService.getCurLoginUser(session);
			rsp=userQueryService.getLookEvaluationInformation(inforQuery,  p,user);
			return gson.toJson(rsp);
		} catch (Exception e) {
			e.printStackTrace();
			Page<Information> rsp=new Page<Information>();
			return gson.toJson(rsp);
		}
		
	}
	@Override
	public String getCommentRecord(InformationQuery informationQuery,Page<Information> p, HttpSession session, HttpServletRequest request) {
		UserInfo user=userService.getCurLoginUser(session);
		String ip=IPUtil.getIpAddr(request);
		if(!informationQuery.getIntputNumber().equals("0")){
			List<UserInfo> userInfos =prisonService.getUserListByAccountOrName((informationQuery.getIntputNumber()));
		 	if (userInfos==null) {
		 		Page<Information> p1=new Page<Information>();
		 		return gson.toJson(p1);
			}else{
				informationQuery.setIntputName(userInfos.get(0).getUserName());
			}
		}else{
			if(!informationQuery.getIntputName().equals("%")){
				List<UserInfo> userInfos =prisonService.getUserListByAccountOrName((informationQuery.getIntputName()));
			 	if (userInfos==null) {
			 		Page<Information> p1=new Page<Information>();
			 		return gson.toJson(p1);
				}else{
					informationQuery.setIntputName(userInfos.get(0).getUserName());
					informationQuery.setUserId(Integer.toString(userInfos.get(0).getUserId()));
				}
			}
		}
		PageReturn pReturn=(PageReturn)session.getAttribute("pageReturn");
		if (pReturn!=null) {
			if (pReturn.isOpen()==true) {
				if (pReturn.getUrl().equals(request.getServletPath())) {
					p.setCurrentPage(pReturn.getPageNum());
					informationQuery=pReturn.getInformationQuery();
					pReturn.setOpen(false);
				}
			}
			
		}
		
		
		Integer port=userService.curLoginUserPowerView(session).getMaxStructure().getId();
		informationQuery.setStructure(Integer.toString(port));
		Page rsp=commentRecordDao.getCommentRecordAll(informationQuery, p,user);
		PageReturn pageReturn=new PageReturn();
		pageReturn.setOpen(false);
		pageReturn.setPageNum(rsp.getCurrentPage());
		pageReturn.setInformationQuery(informationQuery);
		pageReturn.setUrl(request.getServletPath());
		session.setAttribute("pageReturn", pageReturn);	
		return gson.toJson(rsp);
		
//		return gson.toJson(commentRecordDao.getCommentRecordAll(informationQuery,p,userInfo.getUserId()));
	}

	@Override
	public String getRate(InformationQuery informationQuery,Page<com.yuxi.Entity.Information> p, HttpSession session, HttpServletRequest request) {
		UserInfo userInfo=userService.getCurLoginUser(session);
		if(!informationQuery.getIntputNumber().equals("0")){
			List<UserInfo> userInfos =prisonService.getUserListByAccountOrName((informationQuery.getIntputNumber()));
		 	if (userInfos==null) {
		 		Page<Information> p1=new Page<Information>();
		 		return gson.toJson(p1);
			}else{
				informationQuery.setIntputName(userInfos.get(0).getUserName());
			}
		}else{
			if(!informationQuery.getIntputName().equals("%")){
				List<UserInfo> userInfos =prisonService.getUserListByAccountOrName((informationQuery.getIntputName()));
			 	if (userInfos==null) {
			 		Page<Information> p1=new Page<Information>();
			 		return gson.toJson(p1);
				}else{
					informationQuery.setIntputName(userInfos.get(0).getUserName());
					informationQuery.setUserId(Integer.toString(userInfos.get(0).getUserId()));
				}
			}
		}
		PageReturn pReturn=(PageReturn)session.getAttribute("pageReturn");
		if (pReturn!=null) {
			if (pReturn.isOpen()==true) {
				if (pReturn.getUrl().equals(request.getServletPath())) {
					p.setCurrentPage(pReturn.getPageNum());
					informationQuery=pReturn.getInformationQuery();
					pReturn.setOpen(false);
				}
			}
			
		}
		PageReturn pageReturn=new PageReturn();
		pageReturn.setOpen(false);
		pageReturn.setPageNum(p.getCurrentPage());
		pageReturn.setInformationQuery(informationQuery);
		pageReturn.setUrl(request.getServletPath());
		session.setAttribute("pageReturn", pageReturn);	
		return gson.toJson(evaluationRecordDao.getRateAll(informationQuery,p,userInfo.getUserId()));
	}

	@Override
	public String getUserInputTaskContext(InformationQuery inforQuery, Page<TaskInformationView> p, HttpSession session,
			HttpServletRequest request) {
		UserInfo user=userService.getCurLoginUser(session);
		String ip=IPUtil.getIpAddr(request);
		if(!inforQuery.getIntputNumber().equals("0")){
			List<UserInfo> userInfos =prisonService.getUserListByAccountOrName((inforQuery.getIntputNumber()));
		 	if (userInfos==null) {
		 		Page<Information> p1=new Page<Information>();
		 		return gson.toJson(p1);
			}else{
				inforQuery.setIntputName(userInfos.get(0).getUserName());
				inforQuery.setUserId(Integer.toString(userInfos.get(0).getUserId()));
			}
		}else {
			if(!inforQuery.getIntputName().equals("%")){
				List<UserInfo> userInfos =prisonService.getUserListByAccountOrName((inforQuery.getIntputName()));
			 	if (userInfos==null) {
			 		Page<Information> p1=new Page<Information>();
			 		return gson.toJson(p1);
				}else{
					inforQuery.setIntputName(userInfos.get(0).getUserName());
					inforQuery.setUserId(Integer.toString(userInfos.get(0).getUserId()));
				}
			}
		}
		if(!inforQuery.getFinisPersonNum().equals("0")){
			List<UserInfo> userInfos =prisonService.getUserListByAccountOrName((inforQuery.getFinisPersonNum()));
		 	if (userInfos==null) {
		 		Page<Information> p1=new Page<Information>();
		 		return gson.toJson(p1);
			}else{
				inforQuery.setFinisPerson(userInfos.get(0).getUserName());
			}
		}
		PageReturn pReturn=(PageReturn)session.getAttribute("pageReturn");
		if (pReturn!=null) {
			if (pReturn.isOpen()==true) {
				if (pReturn.getUrl().equals(request.getServletPath())) {
					p.setCurrentPage(pReturn.getPageNum());
					inforQuery=pReturn.getInformationQuery();
					pReturn.setOpen(false);
				}
			}
			
		}
		PageReturn pageReturn=new PageReturn();
		pageReturn.setOpen(false);
		pageReturn.setPageNum(p.getCurrentPage());
		pageReturn.setInformationQuery(inforQuery);
		pageReturn.setUrl(request.getServletPath());
		session.setAttribute("pageReturn", pageReturn);	
		return gson.toJson(userQueryService.getAreadyInputTaskContext(inforQuery, user, ip, p));
	}

	@Override
	public String prisonAreaToPrison(Integer infoId,Integer targetPrison,String targetName,String remark,HttpSession session, HttpServletRequest request) {
		try{
			UserInfo u=userService.getCurLoginUser(session);
			String ip=IPUtil.getIpAddr(request);
			PrisonStructure targetStruct=prisonStructureDao.getAllPrisonStructure().get(0);
			if(userInformationService.inforChangeTOPrison(infoId, targetStruct, u, ip, remark)){
				Msg msg=new Msg(true, "提交到监狱成功", System.currentTimeMillis(), null, "提交到监狱");
				return gson.toJson(msg);
			}else{
				Msg msg=new Msg(false, "提交到监狱失败", System.currentTimeMillis(), "10001", "提交到监狱");
				return gson.toJson(msg);
			}
		}catch(Exception e){
			Msg msg=new Msg(false, "提交到监狱失败", System.currentTimeMillis(), "10002", "提交到监狱");
			return gson.toJson(msg);
		}
		
	}

	@Override
	public String prisonToPrisonArea(Integer infoId,Integer targetPrison,String targetName,String targetValue,String remark,HttpSession session, HttpServletRequest request) {
		UserInfo u=userService.getCurLoginUser(session);
		String ip=IPUtil.getIpAddr(request);
		PrisonStructure targetStruct=new PrisonStructure();
		targetStruct.setId(targetPrison);
		targetStruct.setName(targetName);
		targetStruct.setValue(targetValue);	
		
		if(userInformationService.inforChangeTOPrisonArea(infoId, targetStruct, u, ip, remark)){
			Msg msg=new Msg(true, "提交到监区成功", System.currentTimeMillis(), null, "提交到监区");
			return gson.toJson(msg);
		}else{
			Msg msg=new Msg(false, "提交到监区失败", System.currentTimeMillis(), "10001", "提交到监区");
			return gson.toJson(msg);
		}		
	}

	
	
}
